package com.lineage.data.item_etcitem.power;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_OwnCharStatus2;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PanaceaPotion extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(PanaceaPotion.class);
  
  private String[] _panaceaList;
  
  private int _value;
  
  public static ItemExecutor get() {
    return new PanaceaPotion();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int checkPoint = 0;
    String[] panaceaList;
    int i = (panaceaList = this._panaceaList).length;
    int j = 0;
    while (j < i) {
      String value = panaceaList[j];
      if (value.equalsIgnoreCase("STR")) {
        if (pc.getBaseStr() >= this._value)
          checkPoint++; 
      } else if (value.equalsIgnoreCase("CON")) {
        if (pc.getBaseCon() >= this._value)
          checkPoint++; 
      } else if (value.equalsIgnoreCase("DEX")) {
        if (pc.getBaseDex() >= this._value)
          checkPoint++; 
      } else if (value.equalsIgnoreCase("CHA")) {
        if (pc.getBaseCha() >= this._value)
          checkPoint++; 
      } else if (value.equalsIgnoreCase("INT")) {
        if (pc.getBaseInt() >= this._value)
          checkPoint++; 
      } else if (value.equalsIgnoreCase("WIS") && pc.getBaseWis() >= this._value) {
        checkPoint++;
      } 
      j++;
    } 
    if (checkPoint >= this._panaceaList.length) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("你的能力值已经达到要求了。"));
      return;
    } 
    pc.getInventory().removeItem(item, 1L);
    StringBuilder sbr = new StringBuilder();
    sbr.append("你的");
    String[] panaceaList2;
    int length = (panaceaList2 = this._panaceaList).length;
    i = 0;
    while (i < length) {
      String value2 = panaceaList2[i];
      if (value2.equalsIgnoreCase("STR")) {
        pc.addBaseStr(this._value - pc.getBaseStr());
        sbr.append("[力量]");
      } else if (value2.equalsIgnoreCase("CON")) {
        pc.addBaseCon(this._value - pc.getBaseCon());
        sbr.append("[体质]");
      } else if (value2.equalsIgnoreCase("DEX")) {
        pc.addBaseDex(this._value - pc.getBaseDex());
        sbr.append("[敏捷]");
      } else if (value2.equalsIgnoreCase("CHA")) {
        pc.addBaseCha(this._value - pc.getBaseCha());
        sbr.append("[魅力]");
      } else if (value2.equalsIgnoreCase("INT")) {
        pc.addBaseInt(this._value - pc.getBaseInt());
        sbr.append("[智力]");
      } else if (value2.equalsIgnoreCase("WIS")) {
        pc.addBaseWis(this._value - pc.getBaseWis());
        sbr.append("[精神]");
      } 
      i++;
    } 
    pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
    sbr.append("已成功提升至[").append(this._value).append("]点。");
    pc.sendPackets((ServerBasePacket)new S_SystemMessage(sbr.toString()));
    try {
      pc.save();
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._panaceaList = set[1].split("/");
      this._value = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
  }
}
